package ace.module.captcha.sms.core.impl.manager.impl;

import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.manager.spring.AbstractSpringDtoManager;
import ace.module.captcha.sms.api.model.dto.CaptchaSmsItemDto;
import ace.module.captcha.sms.core.impl.dao.entity.CaptchaSmsItem;
import ace.module.captcha.sms.core.impl.manager.CaptchaSmsItemManager;
import ace.module.captcha.sms.core.impl.manager.cache.CaptchaSmsItemCacheDbManager;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 验证码 spring data jdbc querydsl rsql manager implement.
 *
 * @author Caspar
 */
@AllArgsConstructor
@Component
public class CaptchaSmsItemManagerImpl
    extends AbstractSpringDtoManager<CaptchaSmsItem, Long, CaptchaSmsItemDto>
    implements CaptchaSmsItemManager {

  private final CaptchaSmsItemCacheDbManager captchaSmsItemCacheDbManager;

  @Override
  public void remove(Long captchaSmsAppId, String phoneNumber) {
    this.captchaSmsItemCacheDbManager.remove(captchaSmsAppId, phoneNumber);
  }

  @Override
  public Long modify(CaptchaSmsItem captchaSmsItem) {
    return this.captchaSmsItemCacheDbManager.modify(captchaSmsItem);
  }

  @Override
  public Long add(CaptchaSmsItem captchaSmsItem) {
    return this.captchaSmsItemCacheDbManager.add(captchaSmsItem);
  }

  @Override
  public CaptchaSmsItem getByCaptchaSmsAppIdAndPhone(Long captchaSmsAppId, String phone) {
    return this.captchaSmsItemCacheDbManager.getByCaptchaSmsAppIdAndPhone(captchaSmsAppId, phone);
  }

  @Override
  public CaptchaSmsItemDto getDtoByCaptchaSmsAppIdAndPhone(Long captchaSmsAppId, String phone) {
    CaptchaSmsItem captchaSmsItem = this.getByCaptchaSmsAppIdAndPhone(captchaSmsAppId, phone);
    return this.convertToEntityDto(captchaSmsItem);
  }
}
